package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.util.Qiniu;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

@Controller
public class UploadController {

    @PostMapping("/images")
    @ResponseBody
    private Object uploadImage(MultipartFile image){
        HashMap<String, Object> map = new HashMap<String, Object>();
        try {
//          String upload = UploadUtil.upload(image, UploadUtil.IMG_BASE_PATH+"/upload");
            byte[] bytes = image.getBytes();
            String upload = Qiniu.upLoadImage(bytes);
            map.put("url",upload);
            map.put("status",1);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("url","");
            map.put("status",0);
        }
        return map;
    }
}
